﻿using IPC.ListConnect.ListProprety;
using IPC.ListConnect.Profinet;
using IPC.WinForm.Bussiness;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace IPC.WinForm.BaseForm
{
    public partial class FrmUpdateChannel : Form
    {
        public string ChannelName { get; set; }
        public string ChannelType { get; set; }

        private string _oldChannelName = string.Empty;

        public FrmUpdateChannel(string name, string channelType )
        {
            InitializeComponent();
            _oldChannelName=name;
            foreach (var item in typeof(ChannelType).GetEnumNames())
            {
                this.cbChannelType.Items.Add(item);
            }
            this.cbChannelType.Text = channelType;
            this.txtChannelName.Text = name;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            ChannelName = this.txtChannelName.Text;
            ChannelType = this.cbChannelType.Text;
            if (String.IsNullOrWhiteSpace(ChannelName))
            {
                MessageBox.Show("请填写通道名称");
                return;
            }

            foreach (var item in EquipChannels.Instance.EquipChannelList)
            {
                if(item.ChannelName == ChannelName)
                {
                    MessageBox.Show("通道名称已存在！");
                    return;
                }
            }

            foreach (var item in EquipChannels.Instance.EquipChannelList)
            {
                if(item.ChannelName == _oldChannelName)
                {
                    item.ChannelName = ChannelName;
                    break;
                }
            }
            this.DialogResult = DialogResult.OK;
        }
    }
}
